package com.star.percalservice.controller;

import com.star.percalservice.model.dto.UserDTO;
import com.star.percalservice.model.entity.User;
import com.star.percalservice.service.UserService;
import com.star.percalservice.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author star
 * @version 1.0
 * @Description:
 * @DateTime 2025/4/11 23:31
 */

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public R login(String username, String password) {
        return userService.login(username, password);
    }

    @PostMapping("/register")
    public R register(@RequestBody User user) {
        return userService.register(user);
    }

    @PostMapping("/list")
    public R list(@RequestBody UserDTO.UserListDTO userListDTO) {
        return userService.list(userListDTO);
    }

    @PostMapping("/add")
    public R add(@RequestBody User user) {
        return userService.add(user);
    }

    @PostMapping("/update")
    public R update(@RequestBody User user) {
        return userService.update(user);
    }

    @PostMapping("/change-password")
    public R changePassword(Integer id, String password) {
        return userService.changePassword(id, password);
    }



}
